Skip to main content

UiDropdown

A flexible and interactive dropdown menu component for selecting from a list of items.
UiDropdown supports dynamic data sources, search filtering, and automatic positioning within the viewport.

UiDropdown(style = {}, props = {})

Description

UiDropdown provides a composable dropdown selector similar to HTML <select> elements.

It allows users to choose an option from a list, dynamically populate items through getters, and optionally display a label or a search bar.

The dropdown consists of:

  • A main container node (the label and input button)

  • An input button (UiDropdown.Input) that opens/closes the list

  • A popup list (UiDropdown.List) containing selectable items (and an optional search field)


Properties

PropertyTypeDefaultDescription
valueanyundefinedCurrently selected value.
itemsarray<struct>[]List of selectable items ([{label, value}, ...]).
itemsGetterfunctionundefinedOptional function returning a filtered list of items dynamically.
labelstringundefinedText label displayed next to the dropdown.
onChangefunction(value, dropdown)Empty functionCalled when the user selects a new value.
ListUiNodeundefinedActive list node (created when the dropdown opens).
InputUiButtonauto-createdThe clickable button used to open/close the dropdown.
searchstringundefinedPlaceholder for the optional search bar (enables filtering).

Structure

NodeTypePurpose
UiDropdownUiNodeRoot container (label + input).
UiDropdown.InputUiButtonClickable button that toggles the list visibility.
UiDropdown.ListUiNodeFloating panel containing item nodes.
UiDropdown.List.ItemsUiNodeScrollable container of selectable options.
UiDropdown.List.SearchUiTextbox (optional)Input field for live filtering via itemsGetter.

Methods

MethodDescription
createList()Creates and opens the dropdown list. Builds items and positions the list below (or above if needed).
closeList()Destroys the list node and closes the dropdown.
List.computePosition()Ensures the list stays aligned with the dropdown input and within screen bounds.
List.createItems()Builds all dropdown items dynamically from items or itemsGetter.
onStep()Updates the items array from itemsGetter and validates the current selection.
onDraw()Renders the label (if defined).
Input.onDraw()Draws the button background, arrow icon, divider, and current selection text.

Behavior

  • When the input button is clicked, the list opens dynamically as a floating panel.

  • Clicking outside the list automatically closes it.

  • If the selected value becomes invalid (e.g. item removed), the dropdown resets to undefined.

  • The onChange callback fires whenever a new item is selected.

  • When itemsGetter is provided, the dropdown can auto-refresh its contents each frame or via the search field.

  • The dropdown adjusts its position automatically to avoid overflowing the screen.

Search Support

If the search property is set, the dropdown will include a text input (UiTextbox) at the top of the list.

Typing in this field calls:

items = itemsGetter(searchValue)

This allows dynamic filtering, ideal for asset browsers or large data lists.

Visual Notes

  • Arrow icon: drawn using sprUiDropdownArrow on the right side.

  • Hovered items: highlighted with global.UI_COL_INSPECTOR_BG.

  • Selected item: drawn with a filled rectangle.

  • List background: uses global.UI_COL_DROPDOWN_LIST_BG.

  • Search highlight: scrollbar uses global.UI_COL_CHECKBOX_HOVER.


Examples

// Basic dropdown with static items
var dd = new UiDropdown({}, {
label: "Language",
items: [
{ label: "English", value: "en" },
{ label: "Italiano", value: "it" },
{ label: "Deutsch", value: "de" }
],
onChange: function(value, dropdown) {
global.lang = value;
}
});

// Dynamic dropdown with search
var assetDropdown = new UiDropdown({}, {
label: "Model",
search: "Search asset...",
itemsGetter: function(query) {
return array_filter(global.assetList, function(a) {
return string_pos(string_lower(query), string_lower(a.label)) > 0;
});
},
onChange: function(value) {
show_debug_message("Selected asset: " + string(value));
}
});

Performance Notes

Performance Notes

  • Dropdown lists are instantiated on demand and destroyed when closed, saving memory.

  • Scrollbars are auto-enabled for long lists.